Open
Conversation
These operators are needed to parse and evaluate GEMS model expressions from antares_legacy_models.yml, which uses ceil(p/q), max(0, expr), and min(a, b) in variable bounds and constraint expressions for thermal unit commitment models. Changes: - Add FloorNode, CeilNode (unary) and MaxNode, MinNode (binary) AST nodes - Add floor()/ceil() methods on ExpressionNode; maximum()/minimum() factory fns - Extend Expr.g4 grammar with binaryFunction rule; regenerate ANTLR files - Update all visitors: abstract ExpressionVisitor, CopyVisitor, PrinterVisitor, EvaluationVisitor, ExpressionDegreeVisitor, TimeScenarioIndexingVisitor, EqualityVisitor - Register floor/ceil in _FUNCTIONS and max/min in new _BINARY_FUNCTIONS dict - Add tests for parsing, evaluation, and printing of the new operators https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…ExpressionBuilder Add ceil, floor, maximum, minimum implementations to all ExpressionVisitor subclasses that were missing them after the new math operators were added. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
floor(x), ceil(x), max(x,y), min(x,y) are not polynomials when their operands involve variables, so their degree is mathematically undefined (infinity) rather than equal to the operand degree. Also widens ExpressionDegreeVisitor and compute_degree from int to int | float to accommodate math.inf. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…| float When ExpressionDegreeVisitor is parameterized as ExpressionVisitor[int | float], visit() returns int | float everywhere, so all methods that call visit() and were annotated -> int now need -> int | float. https://claude.ai/code/session_01VUYEHTGsxtBYVEVm5c7ysC
…st grammar rule
Replace the separate binaryFunction grammar rule with a unified function rule
using argList, allowing max/min to accept an arbitrary number of operands.
Changes:
- grammar/Expr.g4: add argList rule, merge function/binaryFunction into single
IDENTIFIER '(' argList? ')' # function rule
- Regenerate ANTLR parser files from updated grammar
- expression.py: change MaxNode/MinNode from BinaryOperatorNode to variadic
nodes with operands: List[ExpressionNode]; update maximum()/minimum() helpers
to accept *args
- parse_expression.py: merge visitBinaryFunction into visitFunction using
argList context; remove separate _BINARY_FUNCTIONS dict
- All visitor implementations updated to use node.operands instead of
node.left/node.right (evaluate, print, degree, copy, equality, indexing,
port)
- Tests: add variadic test cases (3+ operands) for parsing, degree, evaluation,
and printer
https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
isort requires stdlib imports (sys, io) before third-party (antlr4) in the generated ExprLexer.py, ExprParser.py, and ExprVisitor.py. https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
Black reformats ExprLexer.py, ExprParser.py and ExprVisitor.py: spaces after colons in type hints, one-item-per-line lists, extra blank lines between class/function definitions. https://claude.ai/code/session_01LLG7eSxsw3XGULyah6ZiB3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.